const path              = require('path');
const uglify            = require("uglifyjs-webpack-plugin");
const htmlPlugin        = require("html-webpack-plugin");
const extractTextPlugin = require("extract-text-webpack-plugin");


var website={
	publicPath:'http://localhost:82/'
};
var webpack = require("webpack");
//获取html-webpack-plugin的参数的方法
var getHtmlPlugin = function (name){
    return {
           minify:{
              removeAttributeQuotes:true
           },
           hash : true,
           template :'./src/view/'+ name +'.html',
           filename : 'view/'+ name +'.html',
           chunks   : ['common',name]
    }
}

module.exports={
   entry:{
     'common' : ['./src/page/common/index.js'],
     'index'  : ['./src/page/index/index.js'],
     'login'  : ['./src/page/login/index.js']
   },
   output:{
      path:path.resolve(__dirname,'dist'),
      filename:'js/[name].js',
      publicPath:website.publicPath
   },
   module : {
      rules:[
   	    {
   	    	test:/\.css$/,
   	    	use:extractTextPlugin.extract({
   	    		fallback:'style-loader',
   	    		use:'css-loader'
   	    	})
   	    },
   	    {
   	    	test:/\.(png|jpg|gif)$/,
   	    	use:[{
   	    		loader:'url-loader',
   	    		options:{
   	    			limit:500,
   	    			outputPath:'images/'
   	    		}
   	    	}]
   	    }
   	  ]
   },
   plugins:[
       // new uglify(), //压缩JS代码
       //CSS的单独打包到文件
       new extractTextPlugin("css/index.css"),
       //独立通用模块js/base.js
       new webpack.optimize.CommonsChunkPlugin({
           name : 'common', //与上面的common
           filename : 'js/base.js'
       }),
       //HTML模板的处理
       new htmlPlugin(getHtmlPlugin('index')),
       new htmlPlugin(getHtmlPlugin('login'))
   ],
   devServer:{
   	 contentBase:path.resolve(__dirname,'dist'),
   	 host:'localhost',
   	 compress:true,
   	 port:82
   }
}